from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

# Create your models here.
LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())


class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        ordering = ('created',)
        verbose_name = 'Snippet'
        verbose_name_plural = 'Snippet'

    def __str__(self):
        return self.code


class Department(models.Model):
    department_name = models.CharField('申请部门', max_length=100)
    the_company = models.CharField(max_length=100, verbose_name='公司', null=True)

    class Meta:  # 这个是用来在admin页面上展示的，因为默认显示的是表名，加上这个就变成中文啦
        verbose_name = '猫号部门信息表'
        verbose_name_plural = "猫号部门信息表"

    def __str__(self):
        return self.department_name


class maohao_info(models.Model):
    name = models.CharField('姓名', max_length=100)
    DepartmenT = models.ForeignKey(Department, null=True, verbose_name=u"申请部门")
    maohao = models.CharField('猫号', max_length=100)
    phone = models.CharField('注册手机号', max_length=100)
    times = models.CharField('注册时间', max_length=100)
    use = models.CharField('使用情况说明用途', max_length=100, null=True)

    class Meta:  # 这个是用来在admin页面上展示的，因为默认显示的是表名，加上这个就变成中文啦
        verbose_name = '猫号信息表'
        verbose_name_plural = "猫号信息表"

    def __str__(self):
        return self.name
